<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/utilities/xajax/xajax_core/xajax.inc.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterCreateDepartment.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
		
	$debug = FirePHP :: getInstance(true);
	$debug -> setEnabled(true);
	
	//Permite eliminar los notices
	error_reporting (E_ALL ^ E_NOTICE);
	
	$_SESSION['debug'] = $debug;
	
	$xajax = new xajax(); 
	 
	$xajax -> register(XAJAX_FUNCTION, 'clickCreateDepartment');
	$xajax -> register(XAJAX_FUNCTION, 'loadExistingBranch');
	$xajax -> processRequest(); 
	 
	$xajax -> configure('javascript URI','../../../utilities/xajax/');
	
	/*load branch*/
	
	function loadExistingBranch() {
		$presenterCreateDepartment = new presenterCreateDepartment();
		
		$dpto = $presenterCreateDepartment -> loadExistingBranch();
		
		$response = new xajaxResponse();
		
		$response -> assign("dpto", "innerHTML", $dpto);
		
		return $response;
	}
	/*create department*/
	
	function clickCreateDepartment($department) {
	
	   $presenterCreateDepartment = new presenterCreateDepartment();
		$GLOBALS['debug'] -> log("DATOS DE LA VISTA DEPARTMENT");
		$GLOBALS['debug'] -> log($department, "branch");
	    $GLOBALS['debug'] -> log($department, "name");
	
	
		$departmentCreation = $presenterCreateDepartment -> clickCreateDepartment ($department);
		
		$response = new xajaxResponse();
		
		if ($departmentCreation == false)
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#FF0000">La operaci&oacute;n fall&oacute;</font>');
		
		else
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#006600">Operaci&oacute;n exitosa</font>');
		
		return $response;
	}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registre un nuevo departamento</title>
<?php 
	$xajax->printJavascript("../../../utilities/xajax/"); 
?>
<link rel="stylesheet" type="text/css" href="../css/formsStyles.css"/>
</head>
<body>
	<script>xajax_loadExistingBranch()</script>
	<div id="formsContainer">
        <div id="title">Registre un nuevo departamento</div><br />
        <form name="department" id="department">
            <table class="formTable" cellspacing="0" cellpadding="5">
                <tr class="even">
                    <td align="right">Sucursal</td>
                    <td align="left">
                    	<div  id ="dpto" >  </div>
                    </td>
                    <td align="right">Nombre</td>
                    <td align="left">
                        <input type="text" name="name" size="32" maxlength="30" />
                    </td>
                </tr>
            </table>
            
            <div id="transactionResult" align="center"></div>
            
            <br /><div id="buttons" align="center">
            	<input type="button" name="buttonCreateDepartment" value="Registrar" onclick="xajax_clickCreateDepartment(xajax.getFormValues('department'))" />
            </div>
        </form>
    </div>
</body>
</html>